version 14.1
set more off

***************************************************************************************************************************
* THIS ROUTINE GENERATES FIGURE IV OF WASEEM (2020) ROLE OF WITHHOLDING ... 
***************************************************************************************************************************


/* TOTAL SALES AND INPUT TAX (QUARTERLY FREQUENCY) */
*----------------------------------------------------

use					"$project_data\STPAK_1992_2003_I.dta", clear
drop 				if regno=="0390999925864"			//dummy number to book wrong-filed returns
duplicates			drop 
keep				if fy>1995 & fy<=2003
keep				taxperiod input output regno tau business_sts tot_sale item_cd 
g					quarter=qofd(taxperiod)
qui					sum quarter
replace				quarter=quarter-r(min)+1
bys					regno quarter:egen inputag=sum(input)
bys					regno quarter:egen outputag=sum(output)
duplicates			drop regno quarter, force
replace				inputag=inputag/tau
replace				outputag=outputag/tau
replace				outputag=tot_sale if business_sts=="3"
bys					quarter:egen inputag_avg=sum(inputag)
bys					quarter:egen outputag_avg=sum(outputag)
g					ind=real(substr(item_cd,1,4))
g					es=0
replace				es=1 if ind>=2700 & ind<2800 
replace				es=0 if ind==2701 | ind==2714
g					sector=0
replace				sector=1 if business_sts=="1"								//manufacturers
replace 			sector=1 if business_sts=="7" & item_cd=="72040000"			//shipbreakers
replace				sector=2 if business_sts=="2"								//importers
replace 			sector=2 if business_sts=="7" & item_cd!="72040000"			//shipbreakers
replace				sector=3 if business_sts=="3"								//exporters
replace				sector=4 if business_sts=="4" |	business_sts=="5" | 		///
					business_sts=="6" 											//middle stages
replace				sector=5 if business_sts=="8"								//service providers
replace				sector=6 if es==1											//energy sector
keep				if sector>0 & sector<=6
bys					quarter sector:egen inputagavg_s=sum(inputag)
bys					quarter sector:egen outputagavg_s=sum(outputag)
duplicates			drop quarter sector, force
#d					;
twoway				(connected inputag_avg quarter,sort lwidth(thick) lcolor(midblue) mcolor(midblue) msymbol(S) lpattern(shortdash))
					(connected outputag_avg quarter, sort lwidth(thick) lcolor(red) mcolor(red) msymbol(D)),
					xlabel(1 "96" 5 "97" 9 "98" 13 "99" 17 "00" 21 "01" 25 "02" 29 "03" 33 "04")
					yscale(titlegap(*5)) ytitle("PKR Billions")
					ylabel(0 0.25e+12 "250" 0.5e+12 "500" 0.75e+12 "750" 1e+12 "1000" 1.25e+12 "1250")
					legend(region(style(none)) label(1 "Inputs") label(2 "Sales") order(2 1))
					graphregion(fcolor(white) style(none) color(white) margin(0 0 0 2)) bgcolor(white);
graph 				export "$project_output\InputOutput_q_agg.eps", replace;
#d					cr

/* MANUFACTURERS */

#d					;
twoway				(connected inputagavg_s quarter if sector==1,sort lwidth(thick) lcolor(midblue) mcolor(midblue) msymbol(S) lpattern(shortdash))
					(connected outputagavg_s quarter if sector==1, sort lwidth(thick) lcolor(red) mcolor(red) msymbol(D)),
					xlabel(1 "96" 5 "97" 9 "98" 13 "99" 17 "00" 21 "01" 25 "02" 29 "03" 33 "04")
					yscale(titlegap(*5)) ytitle("PKR Billions")
					xline(1, lpatter(dash) lcolor(green)) xtitle("Quarter of the Year") xscale(titlegap(*10))
					ylabel(0 0.1e+12 "100" 0.2e+12 "200" 0.3e+12 "300" 0.4e+12 "400" 0.5e+12 "500")
					legend(region(style(none)) label(1 "Inputs") label(2 "Sales") order(2 1))
					graphregion(fcolor(white) style(none) color(white) margin(0 0 0 2)) bgcolor(white);
graph 				export "$project_output\InputOutput_s1.eps", replace;
#d					cr


/* IMPORTERS */

#d					;
twoway				(connected inputagavg_s quarter if sector==2,sort lwidth(thick) lcolor(midblue) mcolor(midblue) msymbol(S) lpattern(shortdash))
					(connected outputagavg_s quarter if sector==2, sort lwidth(thick) lcolor(red) mcolor(red) msymbol(D)),
					xlabel(1 "96" 5 "97" 9 "98" 13 "99" 17 "00" 21 "01" 25 "02" 29 "03" 33 "04")
					yscale(titlegap(*5)) ytitle("PKR Billions")
					xline(5, lpatter(dash) lcolor(green)) xtitle("Quarter of the Year") xscale(titlegap(*10))
					ylabel(0.015e+12 "15" 0.03e+12 "30" 0.045e+12 "45" 0.06e+12 "60" 0.075e+12 "75")
					legend(region(style(none)) label(1 "Inputs") label(2 "Sales") order(2 1))
					graphregion(fcolor(white) style(none) color(white) margin(0 0 0 2)) bgcolor(white);
graph 				export "$project_output\InputOutput_s2.eps", replace;
#d					cr

/* DISTRIBUTORS, WHOLESALERS & RETAILERS */

#d					;
twoway				(connected inputagavg_s quarter if sector==4,sort lwidth(thick) lcolor(midblue) mcolor(midblue) msymbol(S) lpattern(shortdash))
					(connected outputagavg_s quarter if sector==4, sort lwidth(thick) lcolor(red) mcolor(red) msymbol(D)),
					xlabel(1 "96" 5 "97" 9 "98" 13 "99" 17 "00" 21 "01" 25 "02" 29 "03" 33 "04")
					yscale(titlegap(*5)) ytitle("PKR Billions")
					xline(9, lpatter(dash) lcolor(green)) xtitle("Quarter of the Year") xscale(titlegap(*10))
					ylabel(0 0.02e+12 "20" 0.04e+12 "40" 0.06e+12 "60" 0.08e+12 "80" 0.1e+12 "100")
					legend(region(style(none)) label(1 "Inputs") label(2 "Sales") order(2 1))
					graphregion(fcolor(white) style(none) color(white) margin(0 0 0 2)) bgcolor(white);
graph 				export "$project_output\InputOutput_s4.eps", replace;
#d					cr

/* ENERGY SECTOR */

#d					;
twoway				(connected inputagavg_s quarter if sector==6,sort lwidth(thick) lcolor(midblue) mcolor(midblue) msymbol(S) lpattern(shortdash))
					(connected outputagavg_s quarter if sector==6, sort lwidth(thick) lcolor(red) mcolor(red) msymbol(D)),
					xlabel(1 "96" 5 "97" 9 "98" 13 "99" 17 "00" 21 "01" 25 "02" 29 "03" 33 "04")
					yscale(titlegap(*5)) ytitle("PKR Billions") xtitle("Quarter of the Year") xscale(titlegap(*10))
					xline(13, lpatter(dash) lcolor(green)) 
					ylabel(0 1e+11 "100" 2e+11 "200" 3e+11 "300" 4e+11 "400" 5e+11 "500")
					legend(region(style(none)) label(1 "Inputs") label(2 "Sales") order(2 1))
					graphregion(fcolor(white) style(none) color(white) margin(0 0 0 2)) bgcolor(white);
graph 				export "$project_output\InputOutput_s6.eps", replace;
#d					cr

/* SERVICE PROVIDERS */

#d					;
twoway				(connected inputagavg_s quarter if sector==5,sort lwidth(thick) lcolor(midblue) mcolor(midblue) msymbol(S) lpattern(shortdash))
					(connected outputagavg_s quarter if sector==5, sort lwidth(thick) lcolor(red) mcolor(red) msymbol(D)),
					xlabel(1 "96" 5 "97" 9 "98" 13 "99" 17 "00" 21 "01" 25 "02" 29 "03" 33 "04")
					yscale(titlegap(*5)) ytitle("PKR Billions")
					xline(17, lpatter(dash) lcolor(green)) xtitle("Quarter of the Year") xscale(titlegap(*10)) 
					ylabel(0 1e+10 "10" 2e+10 "20" 3e+10 "30" 4e+10 "40" 5e+10 "50")
					legend(region(style(none)) label(1 "Inputs") label(2 "Sales") order(2 1))
					graphregion(fcolor(white) style(none) color(white) margin(0 0 0 2)) bgcolor(white);
graph 				export "$project_output\InputOutput_s5.eps", replace;
#d					cr
